#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 20;
int arr[N];
int n;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		arr[i] = i + 1;
	}
	do {
		for (int i = 0; i < n; i++) {
			cout << arr[i] << " ";
		}
		cout << endl;
	} while (next_permutation(arr,arr+n));
	return 0;
}